TurtleDB
A mini distributed database system
|
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 Value extends Literal 00021 { 00022 private String m_value; 00023 00024 public Value(String s) 00025 { 00026 m_value = s; 00027 } 00028 00029 @Override 00030 public String toString() 00031 { 00032 return m_value; 00033 } 00034 00035 @Override 00036 public boolean equals(Object o) 00037 { 00038 if (o == null) 00039 return false; 00040 if (!(o instanceof Value)) 00041 return false; 00042 return equals((Value) o); 00043 } 00044 00045 public boolean equals(Value v) 00046 { 00047 if (v == null) 00048 return false; 00049 return m_value.compareTo(v.m_value) == 0; 00050 } 00051 00052 @Override 00053 public int hashCode() 00054 { 00055 return m_value.hashCode(); 00056 } 00057 00058 @Override 00059 public int compareTo(Literal o) 00060 { 00061 if (o instanceof Attribute) 00062 return 1; // All attributes go before all values 00063 assert o instanceof Value; 00064 return compareTo((Value) o); 00065 } 00066 00067 public int compareTo(Value o) 00068 { 00069 int compare_value = m_value.compareTo(o.m_value); 00070 if (compare_value < 0) 00071 return -1; 00072 if (compare_value > 0) 00073 return 1; 00074 return 0; 00075 } 00076 }