本文整理汇总了Java中com.google.common.math.IntMath.saturatedAdd方法的典型用法代码示例。如果您正苦于以下问题:Java IntMath.saturatedAdd方法的具体用法?Java IntMath.saturatedAdd怎么用?Java IntMath.saturatedAdd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.math.IntMath
的用法示例。
在下文中一共展示了IntMath.saturatedAdd方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: degree
import com.google.common.math.IntMath; //导入方法依赖的package包/类
@Override
public int degree(N node) {
if (isDirected()) {
return IntMath.saturatedAdd(predecessors(node).size(), successors(node).size());
} else {
Set<N> neighbors = adjacentNodes(node);
int selfLoopCount = (allowsSelfLoops() && neighbors.contains(node)) ? 1 : 0;
return IntMath.saturatedAdd(neighbors.size(), selfLoopCount);
}
}
示例2: degree
import com.google.common.math.IntMath; //导入方法依赖的package包/类
@Override
public int degree(N node) {
if (isDirected()) {
return IntMath.saturatedAdd(inEdges(node).size(), outEdges(node).size());
} else {
return IntMath.saturatedAdd(incidentEdges(node).size(), edgesConnecting(node, node).size());
}
}
示例3: degree
import com.google.common.math.IntMath; //导入方法依赖的package包/类
@Override
public int degree(Object node) {
if (isDirected()) {
return IntMath.saturatedAdd(predecessors(node).size(), successors(node).size());
} else {
Set<N> neighbors = adjacentNodes(node);
int selfLoopCount = (allowsSelfLoops() && neighbors.contains(node)) ? 1 : 0;
return IntMath.saturatedAdd(neighbors.size(), selfLoopCount);
}
}
示例4: degree
import com.google.common.math.IntMath; //导入方法依赖的package包/类
@Override
public int degree(Object node) {
if (isDirected()) {
return IntMath.saturatedAdd(inEdges(node).size(), outEdges(node).size());
} else {
return IntMath.saturatedAdd(incidentEdges(node).size(), edgesConnecting(node, node).size());
}
}
示例5: union
import com.google.common.math.IntMath; //导入方法依赖的package包/类
/**
* Returns an unmodifiable <b>view</b> of the union of two sets. The returned
* set contains all elements that are contained in either backing set.
* Iterating over the returned set iterates first over all the elements of
* {@code set1}, then over each element of {@code set2}, in order, that is not
* contained in {@code set1}.
*
* <p>Results are undefined if {@code set1} and {@code set2} are sets based on
* different equivalence relations (as {@link HashSet}, {@link TreeSet}, and
* the {@link Map#keySet} of an {@code IdentityHashMap} all are).
*/
public static <E> SetView<E> union(final Set<? extends E> set1, final Set<? extends E> set2) {
checkNotNull(set1, "set1");
checkNotNull(set2, "set2");
final Set<? extends E> set2minus1 = difference(set2, set1);
return new SetView<E>() {
@Override
public int size() {
return IntMath.saturatedAdd(set1.size(), set2minus1.size());
}
@Override
public boolean isEmpty() {
return set1.isEmpty() && set2.isEmpty();
}
@Override
public UnmodifiableIterator<E> iterator() {
return Iterators.unmodifiableIterator(
Iterators.concat(set1.iterator(), set2minus1.iterator()));
}
@Override
public Stream<E> stream() {
return Stream.concat(set1.stream(), set2minus1.stream());
}
@Override
public Stream<E> parallelStream() {
return Stream.concat(set1.parallelStream(), set2minus1.parallelStream());
}
@Override
public boolean contains(Object object) {
return set1.contains(object) || set2.contains(object);
}
@Override
public <S extends Set<E>> S copyInto(S set) {
set.addAll(set1);
set.addAll(set2);
return set;
}
@Override
public ImmutableSet<E> immutableCopy() {
return new ImmutableSet.Builder<E>().addAll(set1).addAll(set2).build();
}
};
}
示例6: size
import com.google.common.math.IntMath; //导入方法依赖的package包/类
@Override
public int size() {
return IntMath.saturatedAdd(rest.length, 1);
}
示例7: union
import com.google.common.math.IntMath; //导入方法依赖的package包/类
/**
* Returns an unmodifiable <b>view</b> of the union of two sets. The returned
* set contains all elements that are contained in either backing set.
* Iterating over the returned set iterates first over all the elements of
* {@code set1}, then over each element of {@code set2}, in order, that is not
* contained in {@code set1}.
*
* <p>Results are undefined if {@code set1} and {@code set2} are sets based on
* different equivalence relations (as {@link HashSet}, {@link TreeSet}, and
* the {@link Map#keySet} of an {@code IdentityHashMap} all are).
*/
public static <E> SetView<E> union(
final Set<? extends E> set1, final Set<? extends E> set2) {
checkNotNull(set1, "set1");
checkNotNull(set2, "set2");
final Set<? extends E> set2minus1 = difference(set2, set1);
return new SetView<E>() {
@Override
public int size() {
return IntMath.saturatedAdd(set1.size(), set2minus1.size());
}
@Override
public boolean isEmpty() {
return set1.isEmpty() && set2.isEmpty();
}
@Override
public Iterator<E> iterator() {
return Iterators.unmodifiableIterator(Iterators.concat(set1.iterator(), set2minus1.iterator()));
}
@Override
public boolean contains(Object object) {
return set1.contains(object) || set2.contains(object);
}
@Override
public <S extends Set<E>> S copyInto(S set) {
set.addAll(set1);
set.addAll(set2);
return set;
}
@Override
public ImmutableSet<E> immutableCopy() {
return new ImmutableSet.Builder<E>().addAll(set1).addAll(set2).build();
}
};
}
示例8: union
import com.google.common.math.IntMath; //导入方法依赖的package包/类
/**
* Returns an unmodifiable <b>view</b> of the union of two sets. The returned
* set contains all elements that are contained in either backing set.
* Iterating over the returned set iterates first over all the elements of
* {@code set1}, then over each element of {@code set2}, in order, that is not
* contained in {@code set1}.
*
* <p>Results are undefined if {@code set1} and {@code set2} are sets based on
* different equivalence relations (as {@link HashSet}, {@link TreeSet}, and
* the {@link Map#keySet} of an {@code IdentityHashMap} all are).
*/
public static <E> SetView<E> union(final Set<? extends E> set1, final Set<? extends E> set2) {
checkNotNull(set1, "set1");
checkNotNull(set2, "set2");
final Set<? extends E> set2minus1 = difference(set2, set1);
return new SetView<E>() {
@Override
public int size() {
return IntMath.saturatedAdd(set1.size(), set2minus1.size());
}
@Override
public boolean isEmpty() {
return set1.isEmpty() && set2.isEmpty();
}
@Override
public Iterator<E> iterator() {
return Iterators.unmodifiableIterator(
Iterators.concat(set1.iterator(), set2minus1.iterator()));
}
@Override
public boolean contains(Object object) {
return set1.contains(object) || set2.contains(object);
}
@Override
public <S extends Set<E>> S copyInto(S set) {
set.addAll(set1);
set.addAll(set2);
return set;
}
@Override
public ImmutableSet<E> immutableCopy() {
return new ImmutableSet.Builder<E>().addAll(set1).addAll(set2).build();
}
};
}