Coverage Summary for Class: EdgesConnecting (com.google.common.graph)
| Class | Class, % | Method, % | Line, % |
|---|---|---|---|
| EdgesConnecting | 0% (0/1) | 0% (0/5) | 0% (0/11) |
1 /* 2 * Copyright (C) 2016 The Guava Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.common.graph; 18 19 import static com.google.common.base.Preconditions.checkNotNull; 20 21 import com.google.common.collect.ImmutableSet; 22 import com.google.common.collect.Iterators; 23 import com.google.common.collect.UnmodifiableIterator; 24 import java.util.AbstractSet; 25 import java.util.Map; 26 import javax.annotation.CheckForNull; 27 28 /** 29 * A class to represent the set of edges connecting an (implicit) origin node to a target node. 30 * 31 * <p>The {@link #nodeToOutEdge} map means this class only works on networks without parallel edges. 32 * See {@link MultiEdgesConnecting} for a class that works with parallel edges. 33 * 34 * @author James Sexton 35 * @param <E> Edge parameter type 36 */ 37 @ElementTypesAreNonnullByDefault 38 final class EdgesConnecting<E> extends AbstractSet<E> { 39 40 private final Map<?, E> nodeToOutEdge; 41 private final Object targetNode; 42 43 EdgesConnecting(Map<?, E> nodeToEdgeMap, Object targetNode) { 44 this.nodeToOutEdge = checkNotNull(nodeToEdgeMap); 45 this.targetNode = checkNotNull(targetNode); 46 } 47 48 @Override 49 public UnmodifiableIterator<E> iterator() { 50 E connectingEdge = getConnectingEdge(); 51 return (connectingEdge == null) 52 ? ImmutableSet.<E>of().iterator() 53 : Iterators.singletonIterator(connectingEdge); 54 } 55 56 @Override 57 public int size() { 58 return getConnectingEdge() == null ? 0 : 1; 59 } 60 61 @Override 62 public boolean contains(@CheckForNull Object edge) { 63 E connectingEdge = getConnectingEdge(); 64 return (connectingEdge != null && connectingEdge.equals(edge)); 65 } 66 67 @CheckForNull 68 private E getConnectingEdge() { 69 return nodeToOutEdge.get(targetNode); 70 } 71 }