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

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

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

Maps.safeGet介绍

[英]Delegates to Map#get. Returns null on ClassCastException and NullPointerException.
[中]学员要绘制#获取。在ClassCastException和NullPointerException上返回null。

代码示例

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

@Override
public int count(@Nullable Object element) {
 Collection<V> values = Maps.safeGet(multimap.asMap(), element);
 return (values == null) ? 0 : values.size();
}

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

/**
 * Returns the number of occurrences of {@code element} in this multiset.
 *
 * @param element the element to look for
 * @return the nonnegative number of occurrences of the element
 */
@Override
public int count(@Nullable Object element) {
 AtomicInteger existingCounter = Maps.safeGet(countMap, element);
 return (existingCounter == null) ? 0 : existingCounter.get();
}

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

@Override
public boolean contains(Object o) {
 if (o instanceof Entry) {
  Entry<?, ?> entry = (Entry<?, ?>) o;
  Object key = entry.getKey();
  V value = Maps.safeGet(map(), key);
  return Objects.equal(value, entry.getValue()) && (value != null || map().containsKey(key));
 }
 return false;
}

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

@Override
public boolean contains(Object o) {
 if (o instanceof Entry) {
  Entry<?, ?> entry = (Entry<?, ?>) o;
  Object key = entry.getKey();
  V value = Maps.safeGet(map(), key);
  return Objects.equal(value, entry.getValue()) && (value != null || map().containsKey(key));
 }
 return false;
}

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

@Override
public V get(@Nullable Object rowKey, @Nullable Object columnKey) {
 Map<C, V> row = Maps.safeGet(rowMap(), rowKey);
 return (row == null) ? null : Maps.safeGet(row, columnKey);
}

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

/**
 * Returns the number of occurrences of {@code element} in this multiset.
 *
 * @param element the element to look for
 * @return the nonnegative number of occurrences of the element
 */
@Override
public int count(@NullableDecl Object element) {
 AtomicInteger existingCounter = Maps.safeGet(countMap, element);
 return (existingCounter == null) ? 0 : existingCounter.get();
}

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

@Override
public int count(@Nullable Object element) {
 Count frequency = Maps.safeGet(backingMap, element);
 return (frequency == null) ? 0 : frequency.get();
}

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

@CanIgnoreReturnValue
@Override
public V remove(@Nullable Object rowKey, @Nullable Object columnKey) {
 if ((rowKey == null) || (columnKey == null)) {
  return null;
 }
 Map<C, V> map = safeGet(backingMap, rowKey);
 if (map == null) {
  return null;
 }
 V value = map.remove(columnKey);
 if (map.isEmpty()) {
  backingMap.remove(rowKey);
 }
 return value;
}

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

/**
 * Returns the number of occurrences of {@code element} in this multiset.
 *
 * @param element the element to look for
 * @return the nonnegative number of occurrences of the element
 */
@Override
public int count(@NullableDecl Object element) {
 AtomicInteger existingCounter = Maps.safeGet(countMap, element);
 return (existingCounter == null) ? 0 : existingCounter.get();
}

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

@Override
public int remove(@Nullable Object element, int occurrences) {
 checkNonnegative(occurrences, "occurrences");
 if (occurrences == 0) {
  return count(element);
 }
 Collection<V> values = Maps.safeGet(multimap.asMap(), element);
 if (values == null) {
  return 0;
 }
 int oldCount = values.size();
 if (occurrences >= oldCount) {
  values.clear();
 } else {
  Iterator<V> iterator = values.iterator();
  for (int i = 0; i < occurrences; i++) {
   iterator.next();
   iterator.remove();
  }
 }
 return oldCount;
}

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

@Override
public V get(@NullableDecl Object rowKey, @NullableDecl Object columnKey) {
 Map<C, V> row = Maps.safeGet(rowMap(), rowKey);
 return (row == null) ? null : Maps.safeGet(row, columnKey);
}

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

@Override
public V get(@NullableDecl Object rowKey, @NullableDecl Object columnKey) {
 Map<C, V> row = Maps.safeGet(rowMap(), rowKey);
 return (row == null) ? null : Maps.safeGet(row, columnKey);
}

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

AtomicInteger existingCounter = Maps.safeGet(countMap, element);
if (existingCounter == null) {
 return false;

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

@CanIgnoreReturnValue
@Override
public V remove(@NullableDecl Object rowKey, @NullableDecl Object columnKey) {
 if ((rowKey == null) || (columnKey == null)) {
  return null;
 }
 Map<C, V> map = safeGet(backingMap, rowKey);
 if (map == null) {
  return null;
 }
 V value = map.remove(columnKey);
 if (map.isEmpty()) {
  backingMap.remove(rowKey);
 }
 return value;
}

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

@Override
public int count(@NullableDecl Object element) {
 Count frequency = Maps.safeGet(backingMap, element);
 return (frequency == null) ? 0 : frequency.get();
}

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

@Override
public boolean contains(@Nullable Object rowKey, @Nullable Object columnKey) {
 Map<C, V> row = Maps.safeGet(rowMap(), rowKey);
 return row != null && Maps.safeContainsKey(row, columnKey);
}

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

@CanIgnoreReturnValue
@Override
public V remove(@Nullable Object rowKey, @Nullable Object columnKey) {
 Map<C, V> row = Maps.safeGet(rowMap(), rowKey);
 return (row == null) ? null : Maps.safeRemove(row, columnKey);
}

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

@Override
public boolean contains(@NullableDecl Object rowKey, @NullableDecl Object columnKey) {
 Map<C, V> row = Maps.safeGet(rowMap(), rowKey);
 return row != null && Maps.safeContainsKey(row, columnKey);
}

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

@Override
public boolean contains(@NullableDecl Object rowKey, @NullableDecl Object columnKey) {
 Map<C, V> row = Maps.safeGet(rowMap(), rowKey);
 return row != null && Maps.safeContainsKey(row, columnKey);
}

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

@CanIgnoreReturnValue
@Override
public V remove(@NullableDecl Object rowKey, @NullableDecl Object columnKey) {
 Map<C, V> row = Maps.safeGet(rowMap(), rowKey);
 return (row == null) ? null : Maps.safeRemove(row, columnKey);
}

相关文章