TurtleDB
A mini distributed database system
src/ca/uqac/dim/turtledb/Equality.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 public class Equality extends Condition
00021 {
00022   protected Literal m_left;
00023   protected Literal m_right;
00024   
00025   public Equality(Literal l, Literal r)
00026   {
00027     m_left = l;
00028     m_right = r;
00029   }
00030 
00031   @Override
00032   public boolean evaluate(Tuple t)
00033   {
00034     // attribute = attribute
00035     if (m_left instanceof Attribute && m_right instanceof Attribute)
00036     {
00037       Value left = t.get(m_left);
00038       Value right = t.get(m_right);
00039       return left.equals(right);
00040     }
00041     // attribute = value
00042     if (m_left instanceof Attribute && m_right instanceof Value)
00043     {
00044       Value left = t.get(m_left);
00045       return left.equals(m_right);
00046     }
00047     // value = attribute
00048     if (m_left instanceof Value && m_right instanceof Attribute)
00049     {
00050       return t.get(m_right).equals(m_left);
00051     }
00052     // value = value
00053     if (m_left instanceof Value && m_right instanceof Value)
00054     {
00055       return m_left.equals(m_right);
00056     }
00057     return false;
00058   }
00059   
00060   public void accept(ConditionVisitor v)
00061   {
00062     v.visit(this);
00063   }
00064 
00065 }