001: /*
002: * Copyright 2006-2007 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt.
007: *
008: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
009: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
010: * the license for the specific language governing your rights and limitations.
011: *
012: * Additional Contributor(s): Martin Schmid gridvision engineering GmbH
013: */
014: package org.pentaho.reportdesigner.lib.common.graph;
015:
016: import org.jetbrains.annotations.NotNull;
017:
018: import java.util.HashSet;
019: import java.util.Iterator;
020: import java.util.Set;
021:
022: public class IncidenceContainer {
023:
024: @NotNull
025: private Set<Edge> inIncidentEdges;
026: @NotNull
027: private Set<Edge> outIncidentEdges;
028:
029: @NotNull
030: private Set<Edge> incidentEdges;
031:
032: public IncidenceContainer() {
033: inIncidentEdges = new HashSet<Edge>();
034: outIncidentEdges = new HashSet<Edge>();
035:
036: incidentEdges = new HashSet<Edge>();
037: }
038:
039: public void addOutIncidentEdge(@NotNull
040: Edge e) {
041: outIncidentEdges.add(e);
042: e.setEdgeNumber(outIncidentEdges.size());
043: incidentEdges.add(e);
044: }
045:
046: public void removeOutIncidentEdge(@NotNull
047: Edge e) {
048: outIncidentEdges.remove(e);
049: incidentEdges.remove(e);
050: }
051:
052: public void addInIncidentEdge(@NotNull
053: Edge e) {
054: inIncidentEdges.add(e);
055: e.setEdgeNumber(inIncidentEdges.size());
056: incidentEdges.add(e);
057: }
058:
059: public void removeInIncidentEdge(@NotNull
060: Edge e) {
061: inIncidentEdges.remove(e);
062: incidentEdges.remove(e);
063: }
064:
065: @NotNull
066: public Iterator<Edge> getIncidentEdgeIterator() {
067: return incidentEdges.iterator();
068: }
069:
070: @NotNull
071: public Iterator<Edge> getInIncidentEdgeIterator() {
072: return inIncidentEdges.iterator();
073: }
074:
075: @NotNull
076: public Iterator<Edge> getOutIncidentEdgeIterator() {
077: return outIncidentEdges.iterator();
078: }
079:
080: @NotNull
081: public Edge[] getIncidentEdges() {
082: return incidentEdges.toArray(new Edge[incidentEdges.size()]);
083: }
084:
085: public int getIncidentEdgeCount() {
086: return incidentEdges.size();
087: }
088:
089: public int getInIncidentEdgeCount() {
090: return inIncidentEdges.size();
091: }
092:
093: public int getOutIncidentEdgeCount() {
094: return outIncidentEdges.size();
095: }
096:
097: public boolean hasConnectionTo(@NotNull
098: Vertex vertex) {
099: for (Edge edge : outIncidentEdges) {
100: //noinspection ObjectEquality
101: if (edge.getToVertex() == vertex) {
102: return true;
103: }
104: }
105: return false;
106: }
107: }
|