package com.google.common.graph; import java.util.AbstractSet; import java.util.Set; /* loaded from: classes2.dex */ abstract class IncidentEdgeSet extends AbstractSet> { protected final BaseGraph graph; protected final N node; /* JADX INFO: Access modifiers changed from: package-private */ public IncidentEdgeSet(BaseGraph baseGraph, N n) { this.graph = baseGraph; this.node = n; } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean remove(Object obj) { throw new UnsupportedOperationException(); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public int size() { if (this.graph.isDirected()) { return (this.graph.inDegree(this.node) + this.graph.outDegree(this.node)) - (this.graph.successors((BaseGraph) this.node).contains(this.node) ? 1 : 0); } return this.graph.adjacentNodes(this.node).size(); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean contains(Object obj) { if (!(obj instanceof EndpointPair)) { return false; } EndpointPair endpointPair = (EndpointPair) obj; if (this.graph.isDirected()) { if (!endpointPair.isOrdered()) { return false; } Object source = endpointPair.source(); Object target = endpointPair.target(); return (this.node.equals(source) && this.graph.successors((BaseGraph) this.node).contains(target)) || (this.node.equals(target) && this.graph.predecessors((BaseGraph) this.node).contains(source)); } if (endpointPair.isOrdered()) { return false; } Set adjacentNodes = this.graph.adjacentNodes(this.node); Object nodeU = endpointPair.nodeU(); Object nodeV = endpointPair.nodeV(); return (this.node.equals(nodeV) && adjacentNodes.contains(nodeU)) || (this.node.equals(nodeU) && adjacentNodes.contains(nodeV)); } }