001/** 002 * Copyright (C) 2007 - 2016, 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 */ 019package org.dllearner.prolog; 020 021/** 022 * 023 * @author Sebastian Bader 024 * 025 */ 026public class Number extends Constant { 027 private double value; 028 029 public Number(String src) { 030 value = Double.parseDouble(src); 031 } 032 033 public Number(double value) { 034 this.value = value; 035 } 036 037 public int getIntValue() { 038 return (int) value; 039 } 040 public double getDoubleValue() { 041 return value; 042 } 043 044 @Override 045 public boolean isGround() { 046 return true; 047 } 048 049 @Override 050 public String toString() { 051 return "C["+toPLString()+"]"; 052 } 053 @Override 054 public String toPLString() { 055 if (((double)((int)value)) == value) 056 return ""+(int) value; 057 return ""+value; 058 } 059 060 061 @Override 062 public Term getInstance(Variable variable, Term term) { 063 return new Number(value); 064 } 065 066 @Override 067 public int hashCode() { 068 return (int) value; 069 } 070 071 @Override 072 public boolean equals(Object obj) { 073 if (obj == null) 074 return false; 075 076 Number number; 077 try { 078 number = (Number) obj; 079 } catch (ClassCastException cce) { 080 return false; 081 } 082 083 return value == number.value; 084 } 085 086 @Override 087 public Object clone() { 088 return new Number(value); 089 } 090}