001 /**
002 * Copyright (C) 2007-2011, Jens Lehmann
003 *
004 * This file is part of DL-Learner.
005 *
006 * DL-Learner is free software; you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation; either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * DL-Learner is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with this program. If not, see <http://www.gnu.org/licenses/>.
018 */
019
020 package org.dllearner.prolog;
021
022
023 /**
024 *
025 * @author Sebastian Bader
026 *
027 */
028 public class Number extends Constant {
029 private double value;
030
031 public Number(String src) {
032 value = Double.parseDouble(src);
033 }
034
035 public Number(double value) {
036 this.value = value;
037 }
038
039 public int getIntValue() {
040 return (int) value;
041 }
042 public double getDoubleValue() {
043 return value;
044 }
045
046 @Override
047 public boolean isGround() {
048 return true;
049 }
050
051 @Override
052 public String toString() {
053 return "C["+toPLString()+"]";
054 }
055 @Override
056 public String toPLString() {
057 if (((double)((int)value)) == value)
058 return ""+(int) value;
059 return ""+value;
060 }
061
062
063 @Override
064 public Term getInstance(Variable variable, Term term) {
065 return new Number(value);
066 }
067
068 @Override
069 public int hashCode() {
070 return (int) value;
071 }
072
073 @Override
074 public boolean equals(Object obj) {
075 if (obj == null)
076 return false;
077
078 Number number;
079 try {
080 number = (Number) obj;
081 } catch (ClassCastException cce) {
082 return false;
083 }
084
085 return value == number.value;
086 }
087
088 @Override
089 public Object clone() {
090 return new Number(value);
091 }
092 }