com.google.common.collect.Multiset.remove()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(5.9k)|赞(0)|评价(0)|浏览(142)

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

Multiset.remove介绍

[英]Removes a single occurrence of the specified element from this multiset, if present.

This method refines Collection#remove to further specify that it may not throw an exception in response to element being null or of the wrong type.
[中]从该多重集中删除指定元素的单个匹配项(如果存在)。
此方法细化了集合#remove,以进一步指定它不会在元素为null或类型错误时引发异常。

代码示例

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

@Override
public int remove(Object o, int n) {
 synchronized (mutex) {
  return delegate().remove(o, n);
 }
}

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

@Override
public N removeInEdge(E edge, boolean isSelfLoop) {
 N node = super.removeInEdge(edge, isSelfLoop);
 Multiset<N> predecessors = getReference(predecessorsReference);
 if (predecessors != null) {
  checkState(predecessors.remove(node));
 }
 return node;
}

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

@Override
public N removeOutEdge(E edge) {
 N node = super.removeOutEdge(edge);
 Multiset<N> adjacentNodes = getReference(adjacentNodesReference);
 if (adjacentNodes != null) {
  checkState(adjacentNodes.remove(node));
 }
 return node;
}

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

@Override
public N removeOutEdge(E edge) {
 N node = super.removeOutEdge(edge);
 Multiset<N> successors = getReference(successorsReference);
 if (successors != null) {
  checkState(successors.remove(node));
 }
 return node;
}

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

/** An implementation of {@link Multiset#setCount(Object, int)}. */
static <E> int setCountImpl(Multiset<E> self, E element, int count) {
 checkNonnegative(count, "count");
 int oldCount = self.count(element);
 int delta = count - oldCount;
 if (delta > 0) {
  self.add(element, delta);
 } else if (delta < 0) {
  self.remove(element, -delta);
 }
 return oldCount;
}

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

@Override
 public void remove() {
  checkRemove(canRemove);
  if (totalCount == 1) {
   entryIterator.remove();
  } else {
   multiset.remove(currentEntry.getElement());
  }
  totalCount--;
  canRemove = false;
 }
}

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

@CanIgnoreReturnValue
@Override
public int remove(Object element, int occurrences) {
 return delegate().remove(element, occurrences);
}

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

@CollectionFeature.Require(value = SUPPORTS_REMOVE, absent = ALLOWS_NULL_QUERIES)
public void testRemove_nullForbidden() {
 try {
  getMultiset().remove(null, 2);
  fail("Expected NullPointerException");
 } catch (NullPointerException expected) {
 }
}

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

@MapFeature.Require(SUPPORTS_REMOVE)
public void testKeysRemove() {
 int original = multimap().keys().remove(k0(), 1);
 assertEquals(Math.max(original - 1, 0), multimap().get(k0()).size());
}

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

@CollectionFeature.Require(absent = SUPPORTS_REMOVE)
public void testRemoveUnsupported() {
 try {
  getMultiset().remove(e0(), 2);
  fail("Expected UnsupportedOperationException");
 } catch (UnsupportedOperationException expected) {
 }
}

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

@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testRemove_occurrences_negative() {
 try {
  getMultiset().remove(e0(), -1);
  fail("multiset.remove(E, -1) didn't throw an exception");
 } catch (IllegalArgumentException required) {
 }
}

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

@CollectionSize.Require(absent = ZERO)
public void testEquals_differentElements() {
 Multiset<E> other = HashMultiset.create(getSampleElements());
 other.remove(e0());
 other.add(e3());
 assertFalse("multiset equals a multiset with different elements", getMultiset().equals(other));
}

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

@CollectionFeature.Require(absent = SUPPORTS_REMOVE)
public void testRemove_occurrences_unsupported_absent() {
 // notice: we don't care whether it succeeds, or fails with UOE
 try {
  assertEquals(
    "multiset.remove(absent, 2) didn't return 0 or throw an exception",
    0,
    getMultiset().remove(e3(), 2));
 } catch (UnsupportedOperationException ok) {
 }
}

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

@Override
 public int remove(@Nullable Object element, int occurrences) {
  checkNonnegative(occurrences, "occurrences");
  if (occurrences == 0) {
   return count(element);
  } else {
   return contains(element) ? unfiltered.remove(element, occurrences) : 0;
  }
 }
}

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

@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testRemoveNegative() {
 try {
  getMultiset().remove(e0(), -1);
  fail("Expected IllegalArgumentException");
 } catch (IllegalArgumentException expected) {
 }
 expectUnchanged();
}

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

public void testLinkedKeys() {
 Multimap<String, Integer> map = create();
 map.put("bar", 1);
 map.put("foo", 2);
 map.put("bar", 3);
 map.put("bar", 4);
 assertEquals("[bar=1, foo=2, bar=3, bar=4]", map.entries().toString());
 assertThat(map.keys()).containsExactly("bar", "foo", "bar", "bar").inOrder();
 map.keys().remove("bar"); // bar is no longer the first key!
 assertEquals("{foo=[2], bar=[3, 4]}", map.toString());
}

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

@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testRemove_occurrences_0() {
 int oldCount = getMultiset().count(e0());
 assertEquals(
   "multiset.remove(E, 0) didn't return the old count",
   oldCount,
   getMultiset().remove(e0(), 0));
}

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

public void testRemoveUnsupported() {
 Multiset<String> multiset = new NoRemoveMultiset<>();
 multiset.add("a");
 try {
  multiset.remove("a");
  fail();
 } catch (UnsupportedOperationException expected) {
 }
 assertTrue(multiset.contains("a"));
}

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

@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testRemoveZeroNoOp() {
 int originalCount = getMultiset().count(e0());
 assertEquals("old count", originalCount, getMultiset().remove(e0(), 0));
 expectUnchanged();
}

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

@CollectionSize.Require(absent = ZERO)
@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testRemove_occurrences_present() {
 assertEquals(
   "multiset.remove(present, 2) didn't return the old count",
   1,
   getMultiset().remove(e0(), 2));
 assertFalse(
   "multiset contains present after multiset.remove(present, 2)",
   getMultiset().contains(e0()));
 assertEquals(0, getMultiset().count(e0()));
}

相关文章