001package com.hfg.math; 002 003 004import java.util.Collection; 005import java.util.Map; 006 007import com.hfg.util.CompareUtil; 008import com.hfg.util.collection.OrderedMap; 009import com.hfg.util.collection.OrderedSet; 010 011//------------------------------------------------------------------------------ 012/** 013 Enumeration of standard mathematical relational operators. 014 <div> 015 @author J. Alex Taylor, hairyfatguy.com 016 </div> 017 */ 018//------------------------------------------------------------------------------ 019// com.hfg XML/HTML Coding Library 020// 021// This library is free software; you can redistribute it and/or 022// modify it under the terms of the GNU Lesser General Public 023// License as published by the Free Software Foundation; either 024// version 2.1 of the License, or (at your option) any later version. 025// 026// This library is distributed in the hope that it will be useful, 027// but WITHOUT ANY WARRANTY; without even the implied warranty of 028// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 029// Lesser General Public License for more details. 030// 031// You should have received a copy of the GNU Lesser General Public 032// License along with this library; if not, write to the Free Software 033// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 034// 035// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 036// jataylor@hairyfatguy.com 037//------------------------------------------------------------------------------ 038 039public class RelationalOperator implements Comparable<RelationalOperator> 040{ 041 private String mSymbol; 042 private String mShortName; 043 private int mIndex; 044 045 046 private static int sIndexSrc = 1; 047 private static Map<String, RelationalOperator> sValueMap = new OrderedMap<>(6); 048 049 public static final RelationalOperator EQUALS = new RelationalOperator("=", "EQ"); 050 public static final RelationalOperator NOT_EQUALS = new RelationalOperator("!=", "NE"); 051 public static final RelationalOperator LESS_THAN = new RelationalOperator("<", "LT"); 052 public static final RelationalOperator GREATER_THAN = new RelationalOperator(">", "GT"); 053 public static final RelationalOperator LESS_THAN_OR_EQUAL_TO = new RelationalOperator("<=", "LE"); 054 public static final RelationalOperator GREATER_THAN_OR_EQUAL_TO = new RelationalOperator(">=", "GE"); 055 056 //########################################################################### 057 // CONSTRUCTORS 058 //########################################################################### 059 060 //--------------------------------------------------------------------------- 061 private RelationalOperator(String inSymbol, String inShortName) 062 { 063 mSymbol = inSymbol; 064 mShortName = inShortName; 065 mIndex = sIndexSrc++; 066 sValueMap.put(inSymbol, this); 067 sValueMap.put(inShortName, this); 068 } 069 070 //########################################################################### 071 // PUBLIC METHODS 072 //########################################################################### 073 074 //--------------------------------------------------------------------------- 075 public static Collection<RelationalOperator> values() 076 { 077 return new OrderedSet(sValueMap.values()); 078 } 079 080 //--------------------------------------------------------------------------- 081 public static RelationalOperator valueOf(String inString) 082 { 083 return sValueMap.get(inString); 084 } 085 086 //--------------------------------------------------------------------------- 087 @Override 088 public String toString() 089 { 090 return mSymbol; 091 } 092 093 //--------------------------------------------------------------------------- 094 public String getShortName() 095 { 096 return mShortName; 097 } 098 099 //-------------------------------------------------------------------------- 100 @Override 101 public boolean equals(Object inObj2) 102 { 103 boolean result = false; 104 105 if (inObj2 != null 106 && inObj2 instanceof RelationalOperator) 107 { 108 result = (0 == compareTo((RelationalOperator) inObj2)); 109 } 110 111 return result; 112 } 113 114 //-------------------------------------------------------------------------- 115 @Override 116 public int compareTo(RelationalOperator inObj2) 117 { 118 int result = -1; 119 120 if (inObj2 != null) 121 { 122 result = 0; 123 124 if (this != inObj2) 125 { 126 result = CompareUtil.compare(mIndex, inObj2.mIndex); 127 } 128 } 129 130 return result; 131 } 132 133 //-------------------------------------------------------------------------- 134 @Override 135 public final int hashCode() 136 { 137 return mIndex; 138 } 139 140}