001/* Copyright (C) 2013 TU Dortmund 002 * This file is part of AutomataLib, http://www.automatalib.net/. 003 * 004 * AutomataLib is free software; you can redistribute it and/or 005 * modify it under the terms of the GNU Lesser General Public 006 * License version 3.0 as published by the Free Software Foundation. 007 * 008 * AutomataLib is distributed in the hope that it will be useful, 009 * but WITHOUT ANY WARRANTY; without even the implied warranty of 010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 011 * Lesser General Public License for more details. 012 * 013 * You should have received a copy of the GNU Lesser General Public 014 * License along with AutomataLib; if not, see 015 * http://www.gnu.de/documents/lgpl.en.html. 016 */ 017package net.automatalib.graphs.dot; 018 019import java.io.IOException; 020import java.util.ArrayList; 021import java.util.List; 022import java.util.Map; 023 024import net.automatalib.commons.util.mappings.Mapping; 025 026public class AggregateDOTHelper<N, E> implements GraphDOTHelper<N, E> { 027 028 private final List<GraphDOTHelper<N,? super E>> helpers; 029 030 public AggregateDOTHelper() { 031 helpers = new ArrayList<>(); 032 } 033 034 public AggregateDOTHelper(List<? extends GraphDOTHelper<N, ? super E>> helpers) { 035 this.helpers = new ArrayList<>(helpers); 036 } 037 038 public void add(GraphDOTHelper<N,? super E> helper) { 039 this.helpers.add(helper); 040 } 041 042 @Override 043 public void writePreamble(Appendable a) throws IOException { 044 for(GraphDOTHelper<N,? super E> helper : helpers) 045 helper.writePreamble(a); 046 } 047 048 @Override 049 public void writePostamble(Mapping<N, String> identifiers, Appendable a) 050 throws IOException { 051 for(GraphDOTHelper<N,? super E> helper : helpers) 052 helper.writePostamble(identifiers, a); 053 } 054 055 @Override 056 public boolean getNodeProperties(N node, Map<String, String> properties) { 057 for(GraphDOTHelper<N,? super E> helper : helpers) { 058 if(!helper.getNodeProperties(node, properties)) 059 return false; 060 } 061 return true; 062 } 063 064 @Override 065 public boolean getEdgeProperties(N src, E edge, N tgt, Map<String, String> properties) { 066 for(GraphDOTHelper<N,? super E> helper : helpers) { 067 if(!helper.getEdgeProperties(src, edge, tgt, properties)) 068 return false; 069 } 070 return true; 071 } 072 073}