The following issues were found
guava/src/com/google/common/collect/ImmutableEnumMap.java
8 issues
Line: 84
}
@Override
public boolean equals(@CheckForNull Object object) {
if (object == this) {
return true;
}
if (object instanceof ImmutableEnumMap) {
object = ((ImmutableEnumMap<?, ?>) object).delegate;
Reported by PMD.
Line: 44
return ImmutableMap.of();
case 1:
Entry<K, V> entry = Iterables.getOnlyElement(map.entrySet());
return ImmutableMap.of(entry.getKey(), entry.getValue());
default:
return new ImmutableEnumMap<>(map);
}
}
Reported by PMD.
Line: 44
return ImmutableMap.of();
case 1:
Entry<K, V> entry = Iterables.getOnlyElement(map.entrySet());
return ImmutableMap.of(entry.getKey(), entry.getValue());
default:
return new ImmutableEnumMap<>(map);
}
}
Reported by PMD.
Line: 59
@Override
UnmodifiableIterator<K> keyIterator() {
return Iterators.unmodifiableIterator(delegate.keySet().iterator());
}
@Override
Spliterator<K> keySpliterator() {
return delegate.keySet().spliterator();
Reported by PMD.
Line: 64
@Override
Spliterator<K> keySpliterator() {
return delegate.keySet().spliterator();
}
@Override
public int size() {
return delegate.size();
Reported by PMD.
Line: 84
}
@Override
public boolean equals(@CheckForNull Object object) {
if (object == this) {
return true;
}
if (object instanceof ImmutableEnumMap) {
object = ((ImmutableEnumMap<?, ?>) object).delegate;
Reported by PMD.
Line: 96
@Override
UnmodifiableIterator<Entry<K, V>> entryIterator() {
return Maps.unmodifiableEntryIterator(delegate.entrySet().iterator());
}
@Override
Spliterator<Entry<K, V>> entrySpliterator() {
return CollectSpliterators.map(delegate.entrySet().spliterator(), Maps::unmodifiableEntry);
Reported by PMD.
Line: 101
@Override
Spliterator<Entry<K, V>> entrySpliterator() {
return CollectSpliterators.map(delegate.entrySet().spliterator(), Maps::unmodifiableEntry);
}
@Override
public void forEach(BiConsumer<? super K, ? super V> action) {
delegate.forEach(action);
Reported by PMD.
guava/src/com/google/common/primitives/UnsignedLong.java
8 issues
Line: 42
*/
@GwtCompatible(serializable = true)
@ElementTypesAreNonnullByDefault
public final class UnsignedLong extends Number implements Comparable<UnsignedLong>, Serializable {
private static final long UNSIGNED_MASK = 0x7fffffffffffffffL;
public static final UnsignedLong ZERO = new UnsignedLong(0);
public static final UnsignedLong ONE = new UnsignedLong(1);
Reported by PMD.
Line: 42
*/
@GwtCompatible(serializable = true)
@ElementTypesAreNonnullByDefault
public final class UnsignedLong extends Number implements Comparable<UnsignedLong>, Serializable {
private static final long UNSIGNED_MASK = 0x7fffffffffffffffL;
public static final UnsignedLong ZERO = new UnsignedLong(0);
public static final UnsignedLong ONE = new UnsignedLong(1);
Reported by PMD.
Line: 50
public static final UnsignedLong ONE = new UnsignedLong(1);
public static final UnsignedLong MAX_VALUE = new UnsignedLong(-1L);
private final long value;
private UnsignedLong(long value) {
this.value = value;
}
Reported by PMD.
Line: 134
* @since 14.0
*/
public UnsignedLong plus(UnsignedLong val) {
return fromLongBits(this.value + checkNotNull(val).value);
}
/**
* Returns the result of subtracting this and {@code val}. If the result would have more than 64
* bits, returns the low 64 bits of the result.
Reported by PMD.
Line: 144
* @since 14.0
*/
public UnsignedLong minus(UnsignedLong val) {
return fromLongBits(this.value - checkNotNull(val).value);
}
/**
* Returns the result of multiplying this and {@code val}. If the result would have more than 64
* bits, returns the low 64 bits of the result.
Reported by PMD.
Line: 154
* @since 14.0
*/
public UnsignedLong times(UnsignedLong val) {
return fromLongBits(value * checkNotNull(val).value);
}
/**
* Returns the result of dividing this by {@code val}.
*
Reported by PMD.
Line: 163
* @since 14.0
*/
public UnsignedLong dividedBy(UnsignedLong val) {
return fromLongBits(UnsignedLongs.divide(value, checkNotNull(val).value));
}
/**
* Returns this modulo {@code val}.
*
Reported by PMD.
Line: 172
* @since 14.0
*/
public UnsignedLong mod(UnsignedLong val) {
return fromLongBits(UnsignedLongs.remainder(value, checkNotNull(val).value));
}
/** Returns the value of this {@code UnsignedLong} as an {@code int}. */
@Override
public int intValue() {
Reported by PMD.
guava/src/com/google/common/collect/FilteredMultimapValues.java
8 issues
Line: 40
@ElementTypesAreNonnullByDefault
final class FilteredMultimapValues<K extends @Nullable Object, V extends @Nullable Object>
extends AbstractCollection<V> {
@Weak private final FilteredMultimap<K, V> multimap;
FilteredMultimapValues(FilteredMultimap<K, V> multimap) {
this.multimap = checkNotNull(multimap);
}
Reported by PMD.
Line: 48
@Override
public Iterator<V> iterator() {
return Maps.valueIterator(multimap.entries().iterator());
}
@Override
public boolean contains(@CheckForNull Object o) {
return multimap.containsValue(o);
Reported by PMD.
Line: 64
@Override
public boolean remove(@CheckForNull Object o) {
Predicate<? super Entry<K, V>> entryPredicate = multimap.entryPredicate();
for (Iterator<Entry<K, V>> unfilteredItr = multimap.unfiltered().entries().iterator();
unfilteredItr.hasNext(); ) {
Entry<K, V> entry = unfilteredItr.next();
if (entryPredicate.apply(entry) && Objects.equal(entry.getValue(), o)) {
unfilteredItr.remove();
return true;
Reported by PMD.
Line: 64
@Override
public boolean remove(@CheckForNull Object o) {
Predicate<? super Entry<K, V>> entryPredicate = multimap.entryPredicate();
for (Iterator<Entry<K, V>> unfilteredItr = multimap.unfiltered().entries().iterator();
unfilteredItr.hasNext(); ) {
Entry<K, V> entry = unfilteredItr.next();
if (entryPredicate.apply(entry) && Objects.equal(entry.getValue(), o)) {
unfilteredItr.remove();
return true;
Reported by PMD.
Line: 67
for (Iterator<Entry<K, V>> unfilteredItr = multimap.unfiltered().entries().iterator();
unfilteredItr.hasNext(); ) {
Entry<K, V> entry = unfilteredItr.next();
if (entryPredicate.apply(entry) && Objects.equal(entry.getValue(), o)) {
unfilteredItr.remove();
return true;
}
}
return false;
Reported by PMD.
Line: 78
@Override
public boolean removeAll(Collection<?> c) {
return Iterables.removeIf(
multimap.unfiltered().entries(),
// explicit <Entry<K, V>> is required to build with JDK6
Predicates.<Entry<K, V>>and(
multimap.entryPredicate(), Maps.<V>valuePredicateOnEntries(Predicates.in(c))));
}
Reported by PMD.
Line: 87
@Override
public boolean retainAll(Collection<?> c) {
return Iterables.removeIf(
multimap.unfiltered().entries(),
// explicit <Entry<K, V>> is required to build with JDK6
Predicates.<Entry<K, V>>and(
multimap.entryPredicate(),
Maps.<V>valuePredicateOnEntries(Predicates.not(Predicates.in(c)))));
}
Reported by PMD.
Line: 63
@Override
public boolean remove(@CheckForNull Object o) {
Predicate<? super Entry<K, V>> entryPredicate = multimap.entryPredicate();
for (Iterator<Entry<K, V>> unfilteredItr = multimap.unfiltered().entries().iterator();
unfilteredItr.hasNext(); ) {
Entry<K, V> entry = unfilteredItr.next();
if (entryPredicate.apply(entry) && Objects.equal(entry.getValue(), o)) {
unfilteredItr.remove();
Reported by PMD.
guava/src/com/google/common/graph/StandardMutableValueGraph.java
8 issues
Line: 47
final class StandardMutableValueGraph<N, V> extends StandardValueGraph<N, V>
implements MutableValueGraph<N, V> {
private final ElementOrder<N> incidentEdgeOrder;
/** Constructs a mutable graph with the properties specified in {@code builder}. */
StandardMutableValueGraph(AbstractGraphBuilder<? super N> builder) {
super(builder);
incidentEdgeOrder = builder.incidentEdgeOrder.cast();
Reported by PMD.
Line: 47
final class StandardMutableValueGraph<N, V> extends StandardValueGraph<N, V>
implements MutableValueGraph<N, V> {
private final ElementOrder<N> incidentEdgeOrder;
/** Constructs a mutable graph with the properties specified in {@code builder}. */
StandardMutableValueGraph(AbstractGraphBuilder<? super N> builder) {
super(builder);
incidentEdgeOrder = builder.incidentEdgeOrder.cast();
Reported by PMD.
Line: 101
if (connectionsU == null) {
connectionsU = addNodeInternal(nodeU);
}
V previousValue = connectionsU.addSuccessor(nodeV, value);
GraphConnections<N, V> connectionsV = nodeConnections.get(nodeV);
if (connectionsV == null) {
connectionsV = addNodeInternal(nodeV);
}
connectionsV.addPredecessor(nodeU, value);
Reported by PMD.
Line: 106
if (connectionsV == null) {
connectionsV = addNodeInternal(nodeV);
}
connectionsV.addPredecessor(nodeU, value);
if (previousValue == null) {
checkPositive(++edgeCount);
}
return previousValue;
}
Reported by PMD.
Line: 133
if (allowsSelfLoops()) {
// Remove self-loop (if any) first, so we don't get CME while removing incident edges.
if (connections.removeSuccessor(node) != null) {
connections.removePredecessor(node);
--edgeCount;
}
}
Reported by PMD.
Line: 141
for (N successor : connections.successors()) {
// requireNonNull is safe because the node is a successor.
requireNonNull(nodeConnections.getWithoutCaching(successor)).removePredecessor(node);
--edgeCount;
}
if (isDirected()) { // In undirected graphs, the successor and predecessor sets are equal.
for (N predecessor : connections.predecessors()) {
// requireNonNull is safe because the node is a predecessor.
Reported by PMD.
Line: 148
for (N predecessor : connections.predecessors()) {
// requireNonNull is safe because the node is a predecessor.
checkState(
requireNonNull(nodeConnections.getWithoutCaching(predecessor)).removeSuccessor(node)
!= null);
--edgeCount;
}
}
nodeConnections.remove(node);
Reported by PMD.
Line: 171
return null;
}
V previousValue = connectionsU.removeSuccessor(nodeV);
if (previousValue != null) {
connectionsV.removePredecessor(nodeU);
checkNonNegative(--edgeCount);
}
return previousValue;
Reported by PMD.
guava/src/com/google/common/graph/StandardMutableNetwork.java
8 issues
Line: 88
EndpointPair<N> existingIncidentNodes = incidentNodes(edge);
EndpointPair<N> newIncidentNodes = EndpointPair.of(this, nodeU, nodeV);
checkArgument(
existingIncidentNodes.equals(newIncidentNodes),
REUSING_EDGE,
edge,
existingIncidentNodes,
newIncidentNodes);
return false;
Reported by PMD.
Line: 98
NetworkConnections<N, E> connectionsU = nodeConnections.get(nodeU);
if (!allowsParallelEdges()) {
checkArgument(
!(connectionsU != null && connectionsU.successors().contains(nodeV)),
PARALLEL_EDGES_NOT_ALLOWED,
nodeU,
nodeV);
}
boolean isSelfLoop = nodeU.equals(nodeV);
Reported by PMD.
Line: 111
if (connectionsU == null) {
connectionsU = addNodeInternal(nodeU);
}
connectionsU.addOutEdge(edge, nodeV);
NetworkConnections<N, E> connectionsV = nodeConnections.get(nodeV);
if (connectionsV == null) {
connectionsV = addNodeInternal(nodeV);
}
connectionsV.addInEdge(edge, nodeU, isSelfLoop);
Reported by PMD.
Line: 116
if (connectionsV == null) {
connectionsV = addNodeInternal(nodeV);
}
connectionsV.addInEdge(edge, nodeU, isSelfLoop);
edgeToReferenceNode.put(edge, nodeU);
return true;
}
@Override
Reported by PMD.
Line: 159
// requireNonNull is safe because of the edgeToReferenceNode check above.
NetworkConnections<N, E> connectionsU = requireNonNull(nodeConnections.get(nodeU));
N nodeV = connectionsU.adjacentNode(edge);
NetworkConnections<N, E> connectionsV = requireNonNull(nodeConnections.get(nodeV));
connectionsU.removeOutEdge(edge);
connectionsV.removeInEdge(edge, allowsSelfLoops() && nodeU.equals(nodeV));
edgeToReferenceNode.remove(edge);
return true;
Reported by PMD.
Line: 161
NetworkConnections<N, E> connectionsU = requireNonNull(nodeConnections.get(nodeU));
N nodeV = connectionsU.adjacentNode(edge);
NetworkConnections<N, E> connectionsV = requireNonNull(nodeConnections.get(nodeV));
connectionsU.removeOutEdge(edge);
connectionsV.removeInEdge(edge, allowsSelfLoops() && nodeU.equals(nodeV));
edgeToReferenceNode.remove(edge);
return true;
}
Reported by PMD.
Line: 162
N nodeV = connectionsU.adjacentNode(edge);
NetworkConnections<N, E> connectionsV = requireNonNull(nodeConnections.get(nodeV));
connectionsU.removeOutEdge(edge);
connectionsV.removeInEdge(edge, allowsSelfLoops() && nodeU.equals(nodeV));
edgeToReferenceNode.remove(edge);
return true;
}
private NetworkConnections<N, E> newConnections() {
Reported by PMD.
Line: 162
N nodeV = connectionsU.adjacentNode(edge);
NetworkConnections<N, E> connectionsV = requireNonNull(nodeConnections.get(nodeV));
connectionsU.removeOutEdge(edge);
connectionsV.removeInEdge(edge, allowsSelfLoops() && nodeU.equals(nodeV));
edgeToReferenceNode.remove(edge);
return true;
}
private NetworkConnections<N, E> newConnections() {
Reported by PMD.
guava/src/com/google/common/graph/NetworkBuilder.java
8 issues
Line: 71
*/
@Beta
@ElementTypesAreNonnullByDefault
public final class NetworkBuilder<N, E> extends AbstractGraphBuilder<N> {
boolean allowsParallelEdges = false;
ElementOrder<? super E> edgeOrder = ElementOrder.insertion();
Optional<Integer> expectedEdgeCount = Optional.absent();
/** Creates a new instance with the specified edge directionality. */
Reported by PMD.
Line: 72
@Beta
@ElementTypesAreNonnullByDefault
public final class NetworkBuilder<N, E> extends AbstractGraphBuilder<N> {
boolean allowsParallelEdges = false;
ElementOrder<? super E> edgeOrder = ElementOrder.insertion();
Optional<Integer> expectedEdgeCount = Optional.absent();
/** Creates a new instance with the specified edge directionality. */
private NetworkBuilder(boolean directed) {
Reported by PMD.
Line: 72
@Beta
@ElementTypesAreNonnullByDefault
public final class NetworkBuilder<N, E> extends AbstractGraphBuilder<N> {
boolean allowsParallelEdges = false;
ElementOrder<? super E> edgeOrder = ElementOrder.insertion();
Optional<Integer> expectedEdgeCount = Optional.absent();
/** Creates a new instance with the specified edge directionality. */
private NetworkBuilder(boolean directed) {
Reported by PMD.
Line: 72
@Beta
@ElementTypesAreNonnullByDefault
public final class NetworkBuilder<N, E> extends AbstractGraphBuilder<N> {
boolean allowsParallelEdges = false;
ElementOrder<? super E> edgeOrder = ElementOrder.insertion();
Optional<Integer> expectedEdgeCount = Optional.absent();
/** Creates a new instance with the specified edge directionality. */
private NetworkBuilder(boolean directed) {
Reported by PMD.
Line: 73
@ElementTypesAreNonnullByDefault
public final class NetworkBuilder<N, E> extends AbstractGraphBuilder<N> {
boolean allowsParallelEdges = false;
ElementOrder<? super E> edgeOrder = ElementOrder.insertion();
Optional<Integer> expectedEdgeCount = Optional.absent();
/** Creates a new instance with the specified edge directionality. */
private NetworkBuilder(boolean directed) {
super(directed);
Reported by PMD.
Line: 73
@ElementTypesAreNonnullByDefault
public final class NetworkBuilder<N, E> extends AbstractGraphBuilder<N> {
boolean allowsParallelEdges = false;
ElementOrder<? super E> edgeOrder = ElementOrder.insertion();
Optional<Integer> expectedEdgeCount = Optional.absent();
/** Creates a new instance with the specified edge directionality. */
private NetworkBuilder(boolean directed) {
super(directed);
Reported by PMD.
Line: 74
public final class NetworkBuilder<N, E> extends AbstractGraphBuilder<N> {
boolean allowsParallelEdges = false;
ElementOrder<? super E> edgeOrder = ElementOrder.insertion();
Optional<Integer> expectedEdgeCount = Optional.absent();
/** Creates a new instance with the specified edge directionality. */
private NetworkBuilder(boolean directed) {
super(directed);
}
Reported by PMD.
Line: 74
public final class NetworkBuilder<N, E> extends AbstractGraphBuilder<N> {
boolean allowsParallelEdges = false;
ElementOrder<? super E> edgeOrder = ElementOrder.insertion();
Optional<Integer> expectedEdgeCount = Optional.absent();
/** Creates a new instance with the specified edge directionality. */
private NetworkBuilder(boolean directed) {
super(directed);
}
Reported by PMD.
guava/src/com/google/common/util/concurrent/ExecutionList.java
8 issues
Line: 148
// Log it and keep going -- bad runnable and/or executor. Don't punish the other runnables if
// we're given a bad one. We only catch RuntimeException because we want Errors to propagate
// up.
log.log(
Level.SEVERE,
"RuntimeException while executing runnable " + runnable + " with executor " + executor,
e);
}
}
Reported by PMD.
Line: 54
*/
@GuardedBy("this")
@CheckForNull
private RunnableExecutorPair runnables;
@GuardedBy("this")
private boolean executed;
/** Creates a new, empty {@link ExecutionList}. */
Reported by PMD.
Line: 57
private RunnableExecutorPair runnables;
@GuardedBy("this")
private boolean executed;
/** Creates a new, empty {@link ExecutionList}. */
public ExecutionList() {}
/**
Reported by PMD.
Line: 113
}
executed = true;
list = runnables;
runnables = null; // allow GC to free listeners even if this stays around for a while.
}
// If we succeeded then list holds all the runnables we to execute. The pairs in the stack are
// in the opposite order from how they were added so we need to reverse the list to fulfill our
// contract.
// This is somewhat annoying, but turns out to be very fast in practice. Alternatively, we could
Reported by PMD.
Line: 144
private static void executeListener(Runnable runnable, Executor executor) {
try {
executor.execute(runnable);
} catch (RuntimeException e) {
// Log it and keep going -- bad runnable and/or executor. Don't punish the other runnables if
// we're given a bad one. We only catch RuntimeException because we want Errors to propagate
// up.
log.log(
Level.SEVERE,
Reported by PMD.
Line: 156
}
private static final class RunnableExecutorPair {
final Runnable runnable;
final Executor executor;
@CheckForNull RunnableExecutorPair next;
RunnableExecutorPair(
Runnable runnable, Executor executor, @CheckForNull RunnableExecutorPair next) {
Reported by PMD.
Line: 157
private static final class RunnableExecutorPair {
final Runnable runnable;
final Executor executor;
@CheckForNull RunnableExecutorPair next;
RunnableExecutorPair(
Runnable runnable, Executor executor, @CheckForNull RunnableExecutorPair next) {
this.runnable = runnable;
Reported by PMD.
Line: 158
private static final class RunnableExecutorPair {
final Runnable runnable;
final Executor executor;
@CheckForNull RunnableExecutorPair next;
RunnableExecutorPair(
Runnable runnable, Executor executor, @CheckForNull RunnableExecutorPair next) {
this.runnable = runnable;
this.executor = executor;
Reported by PMD.
guava/src/com/google/common/graph/IncidentEdgeSet.java
8 issues
Line: 29
*/
@ElementTypesAreNonnullByDefault
abstract class IncidentEdgeSet<N> extends AbstractSet<EndpointPair<N>> {
final N node;
final BaseGraph<N> graph;
IncidentEdgeSet(BaseGraph<N> graph, N node) {
this.graph = graph;
this.node = node;
Reported by PMD.
Line: 30
@ElementTypesAreNonnullByDefault
abstract class IncidentEdgeSet<N> extends AbstractSet<EndpointPair<N>> {
final N node;
final BaseGraph<N> graph;
IncidentEdgeSet(BaseGraph<N> graph, N node) {
this.graph = graph;
this.node = node;
}
Reported by PMD.
Line: 47
if (graph.isDirected()) {
return graph.inDegree(node)
+ graph.outDegree(node)
- (graph.successors(node).contains(node) ? 1 : 0);
} else {
return graph.adjacentNodes(node).size();
}
}
Reported by PMD.
Line: 49
+ graph.outDegree(node)
- (graph.successors(node).contains(node) ? 1 : 0);
} else {
return graph.adjacentNodes(node).size();
}
}
@Override
public boolean contains(@CheckForNull Object obj) {
Reported by PMD.
Line: 67
Object source = endpointPair.source();
Object target = endpointPair.target();
return (node.equals(source) && graph.successors(node).contains(target))
|| (node.equals(target) && graph.predecessors(node).contains(source));
} else {
if (endpointPair.isOrdered()) {
return false;
}
Reported by PMD.
Line: 68
Object source = endpointPair.source();
Object target = endpointPair.target();
return (node.equals(source) && graph.successors(node).contains(target))
|| (node.equals(target) && graph.predecessors(node).contains(source));
} else {
if (endpointPair.isOrdered()) {
return false;
}
Set<N> adjacent = graph.adjacentNodes(node);
Reported by PMD.
Line: 77
Object nodeU = endpointPair.nodeU();
Object nodeV = endpointPair.nodeV();
return (node.equals(nodeV) && adjacent.contains(nodeU))
|| (node.equals(nodeU) && adjacent.contains(nodeV));
}
}
}
Reported by PMD.
Line: 78
Object nodeV = endpointPair.nodeV();
return (node.equals(nodeV) && adjacent.contains(nodeU))
|| (node.equals(nodeU) && adjacent.contains(nodeV));
}
}
}
Reported by PMD.
guava/src/com/google/common/collect/JdkBackedImmutableMultiset.java
8 issues
Line: 33
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
final class JdkBackedImmutableMultiset<E> extends ImmutableMultiset<E> {
private final Map<E, Integer> delegateMap;
private final ImmutableList<Entry<E>> entries;
private final long size;
static <E> ImmutableMultiset<E> create(Collection<? extends Entry<? extends E>> entries) {
Reported by PMD.
Line: 34
@GwtCompatible
@ElementTypesAreNonnullByDefault
final class JdkBackedImmutableMultiset<E> extends ImmutableMultiset<E> {
private final Map<E, Integer> delegateMap;
private final ImmutableList<Entry<E>> entries;
private final long size;
static <E> ImmutableMultiset<E> create(Collection<? extends Entry<? extends E>> entries) {
@SuppressWarnings("unchecked")
Reported by PMD.
Line: 35
@ElementTypesAreNonnullByDefault
final class JdkBackedImmutableMultiset<E> extends ImmutableMultiset<E> {
private final Map<E, Integer> delegateMap;
private final ImmutableList<Entry<E>> entries;
private final long size;
static <E> ImmutableMultiset<E> create(Collection<? extends Entry<? extends E>> entries) {
@SuppressWarnings("unchecked")
Entry<E>[] entriesArray = entries.toArray(new Entry[0]);
Reported by PMD.
Line: 36
final class JdkBackedImmutableMultiset<E> extends ImmutableMultiset<E> {
private final Map<E, Integer> delegateMap;
private final ImmutableList<Entry<E>> entries;
private final long size;
static <E> ImmutableMultiset<E> create(Collection<? extends Entry<? extends E>> entries) {
@SuppressWarnings("unchecked")
Entry<E>[] entriesArray = entries.toArray(new Entry[0]);
Map<E, Integer> delegateMap = Maps.newHashMapWithExpectedSize(entriesArray.length);
Reported by PMD.
Line: 36
final class JdkBackedImmutableMultiset<E> extends ImmutableMultiset<E> {
private final Map<E, Integer> delegateMap;
private final ImmutableList<Entry<E>> entries;
private final long size;
static <E> ImmutableMultiset<E> create(Collection<? extends Entry<? extends E>> entries) {
@SuppressWarnings("unchecked")
Entry<E>[] entriesArray = entries.toArray(new Entry[0]);
Map<E, Integer> delegateMap = Maps.newHashMapWithExpectedSize(entriesArray.length);
Reported by PMD.
Line: 45
long size = 0;
for (int i = 0; i < entriesArray.length; i++) {
Entry<E> entry = entriesArray[i];
int count = entry.getCount();
size += count;
E element = checkNotNull(entry.getElement());
delegateMap.put(element, count);
if (!(entry instanceof Multisets.ImmutableEntry)) {
entriesArray[i] = Multisets.immutableEntry(element, count);
Reported by PMD.
Line: 47
Entry<E> entry = entriesArray[i];
int count = entry.getCount();
size += count;
E element = checkNotNull(entry.getElement());
delegateMap.put(element, count);
if (!(entry instanceof Multisets.ImmutableEntry)) {
entriesArray[i] = Multisets.immutableEntry(element, count);
}
}
Reported by PMD.
Line: 69
return delegateMap.getOrDefault(element, 0);
}
@CheckForNull private transient ImmutableSet<E> elementSet;
@Override
public ImmutableSet<E> elementSet() {
ImmutableSet<E> result = elementSet;
return (result == null) ? elementSet = new ElementSet<E>(entries, this) : result;
Reported by PMD.
guava/src/com/google/common/graph/ImmutableNetwork.java
8 issues
Line: 87
for (N node : network.nodes()) {
nodeConnections.put(node, connectionsOf(network, node));
}
return nodeConnections.build();
}
private static <N, E> Map<E, N> getEdgeToReferenceNode(Network<N, E> network) {
// ImmutableMap.Builder maintains the order of the elements as inserted, so the map will have
// whatever ordering the network's edges do, so ImmutableSortedMap is unnecessary even if the
Reported by PMD.
Line: 96
// input edges are sorted.
ImmutableMap.Builder<E, N> edgeToReferenceNode = ImmutableMap.builder();
for (E edge : network.edges()) {
edgeToReferenceNode.put(edge, network.incidentNodes(edge).nodeU());
}
return edgeToReferenceNode.build();
}
private static <N, E> NetworkConnections<N, E> connectionsOf(Network<N, E> network, N node) {
Reported by PMD.
Line: 98
for (E edge : network.edges()) {
edgeToReferenceNode.put(edge, network.incidentNodes(edge).nodeU());
}
return edgeToReferenceNode.build();
}
private static <N, E> NetworkConnections<N, E> connectionsOf(Network<N, E> network, N node) {
if (network.isDirected()) {
Map<E, N> inEdgeMap = Maps.asMap(network.inEdges(node), sourceNodeFn(network));
Reported by PMD.
Line: 105
if (network.isDirected()) {
Map<E, N> inEdgeMap = Maps.asMap(network.inEdges(node), sourceNodeFn(network));
Map<E, N> outEdgeMap = Maps.asMap(network.outEdges(node), targetNodeFn(network));
int selfLoopCount = network.edgesConnecting(node, node).size();
return network.allowsParallelEdges()
? DirectedMultiNetworkConnections.ofImmutable(inEdgeMap, outEdgeMap, selfLoopCount)
: DirectedNetworkConnections.ofImmutable(inEdgeMap, outEdgeMap, selfLoopCount);
} else {
Map<E, N> incidentEdgeMap =
Reported by PMD.
Line: 122
return new Function<E, N>() {
@Override
public N apply(E edge) {
return network.incidentNodes(edge).source();
}
};
}
private static <N, E> Function<E, N> targetNodeFn(final Network<N, E> network) {
Reported by PMD.
Line: 131
return new Function<E, N>() {
@Override
public N apply(E edge) {
return network.incidentNodes(edge).target();
}
};
}
private static <N, E> Function<E, N> adjacentNodeFn(final Network<N, E> network, final N node) {
Reported by PMD.
Line: 140
return new Function<E, N>() {
@Override
public N apply(E edge) {
return network.incidentNodes(edge).adjacentNode(node);
}
};
}
/**
Reported by PMD.
Line: 170
*/
public static class Builder<N, E> {
private final MutableNetwork<N, E> mutableNetwork;
Builder(NetworkBuilder<N, E> networkBuilder) {
this.mutableNetwork = networkBuilder.build();
}
Reported by PMD.