本文整理了Java中com.google.common.collect.Maps.safeGet()
方法的一些代码示例,展示了Maps.safeGet()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Maps.safeGet()
方法的具体详情如下:
包路径:com.google.common.collect.Maps
类名称: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);
}
内容来源于网络,如有侵权,请联系作者删除!