001 package lrs.visitor;
002 import lrs.*;
003 import logic.*;
004
005
006 // This class is an IComparable compatible object that holds integer values.
007
008 public class CompareObject implements IComparable{
009 private int _value;
010 private static final IBooleanFactory _BF = BooleanFactory.Singleton;
011
012 // Construct the object with an integer value
013 public CompareObject( int value) {
014 _value = value;
015 }
016
017 // Construct the object with a string value
018 public CompareObject( String strValue) {
019 _value = Integer.parseInt(strValue);
020 }
021
022 // returns the integer value held as an integer
023 public int getValue() {
024 return _value;
025 }
026
027 // returns the integer value held as a string
028 public String getString() {
029 return String.valueOf(_value);
030 }
031
032 // Compare returns true if the object's value is less than the input value.
033 public IBoolean compare(IComparable x) {
034 return _BF.makeBoolean(_value < ((CompareObject)x).getValue());
035 //return( (_value < ((CompareObject)x).getValue() )? true: false);
036 }
037
038 // Equals returns true if the object's value is equal to the input's value.
039 public IBoolean equals(IComparable x) {
040 return _BF.makeBoolean(_value == ((CompareObject)x).getValue());
041 // return( (_value == ((CompareObject)x).getValue() )? true: false);
042 }
043 }