TurtleDB
A mini distributed database system
src/ca/uqac/dim/turtledb/GraphvizConditionVisitor.java
Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002     Simple distributed database engine
00003     Copyright (C) 2012  Sylvain Hallé
00004 
00005     This program is free software: you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation, either version 3 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017  -------------------------------------------------------------------------*/
00018 package ca.uqac.dim.turtledb;
00019 
00020 import java.util.*;
00021 
00022 public class GraphvizConditionVisitor extends ConditionVisitor
00023 {
00024   protected Stack<String> m_parts;
00025 
00026   public GraphvizConditionVisitor() {
00027     m_parts = new Stack<String>();
00028   }
00029 
00030   @Override
00031   public void visit(LogicalAnd c)
00032   {
00033     visitNAry("&land;", c);
00034   }
00035   
00036   protected void visitNAry(String operator, NAryCondition c)
00037   {
00038     StringBuilder out = new StringBuilder();
00039     int len = c.getArity();
00040     for (int i = 0; i < len; i++)
00041     {
00042       String op = m_parts.pop();
00043       if (i > 0)
00044         out.append(operator);
00045       out.append(op);
00046     }
00047     m_parts.push(out.toString());
00048   }
00049 
00050   @Override
00051   public void visit(LogicalOr c)
00052   {
00053     visitNAry("&lor;", c);
00054   }
00055 
00056   @Override
00057   public void visit(Equality c)
00058   {
00059     StringBuilder out = new StringBuilder();
00060     out.append(c.m_left.toString()).append("=").append(c.m_right.toString());
00061     m_parts.push(out.toString());
00062   }
00063   
00064   public String getGraphviz()
00065   {
00066     String out = m_parts.peek();
00067     return out;
00068   }
00069 
00070 }