Coverage Summary for Class: IncidentEdgeSet (com.google.common.graph)

Class Class, % Method, % Line, %
IncidentEdgeSet 0% (0/1) 0% (0/4) 0% (0/26)


1 /* 2  * Copyright (C) 2019 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 java.util.AbstractSet; 20 import java.util.Set; 21 import javax.annotation.CheckForNull; 22  23 /** 24  * Abstract base class for an incident edges set that allows different implementations of {@link 25  * AbstractSet#iterator()}. 26  */ 27 @ElementTypesAreNonnullByDefault 28 abstract class IncidentEdgeSet<N> extends AbstractSet<EndpointPair<N>> { 29  final N node; 30  final BaseGraph<N> graph; 31  32  IncidentEdgeSet(BaseGraph<N> graph, N node) { 33  this.graph = graph; 34  this.node = node; 35  } 36  37  @Override 38  public boolean remove(@CheckForNull Object o) { 39  throw new UnsupportedOperationException(); 40  } 41  42  @Override 43  public int size() { 44  if (graph.isDirected()) { 45  return graph.inDegree(node) 46  + graph.outDegree(node) 47  - (graph.successors(node).contains(node) ? 1 : 0); 48  } else { 49  return graph.adjacentNodes(node).size(); 50  } 51  } 52  53  @Override 54  public boolean contains(@CheckForNull Object obj) { 55  if (!(obj instanceof EndpointPair)) { 56  return false; 57  } 58  EndpointPair<?> endpointPair = (EndpointPair<?>) obj; 59  60  if (graph.isDirected()) { 61  if (!endpointPair.isOrdered()) { 62  return false; 63  } 64  65  Object source = endpointPair.source(); 66  Object target = endpointPair.target(); 67  return (node.equals(source) && graph.successors(node).contains(target)) 68  || (node.equals(target) && graph.predecessors(node).contains(source)); 69  } else { 70  if (endpointPair.isOrdered()) { 71  return false; 72  } 73  Set<N> adjacent = graph.adjacentNodes(node); 74  Object nodeU = endpointPair.nodeU(); 75  Object nodeV = endpointPair.nodeV(); 76  77  return (node.equals(nodeV) && adjacent.contains(nodeU)) 78  || (node.equals(nodeU) && adjacent.contains(nodeV)); 79  } 80  } 81 }