Results 1 to 2 of 2
Thread: Checking for forbidden words
- 04-15-2011, 11:43 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 43
- Rep Power
- 0
Checking for forbidden words
I'm trying to put together a method that check for predefined vars. If a user tries to use a predefined variable not mapping is supposed to take place.
Method to check for predefined.
Usage:Java Code:static boolean isVarAllowed() { if(st.getWord() == "e" || //getWord() returns String st.getWord() == "pi" || st.getWord() == "sin" || st.getWord() == "cos" || st.getWord() == "log" || st.getWord() == "exp" || st.getWord() == "ans") { return false; } else { return true; } }
The mapping works, but I can't get it do deny over mapping. As it is now I'm loosing stuff like pi if the user tries to save stuff in pi. I other words, all mappings are allowed now. Well, as I said, that's not what I what. :-/Java Code:if(isVarAllowed() == true) { System.out.println("Test: It's mapping."); map.put(st.getWord(), new Double(res)); }Last edited by überfuzz; 04-15-2011 at 11:46 AM. Reason: Stupid title
- 04-15-2011, 12:08 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
Don't compare Strings for equality like that: use the equals() method. Also, why don't you use a simple Set that contains the forbidden words?
kind regards,Java Code:private static final Set<String> forbidden= new HashSet<String>() {{ add("e"); add("pi"); ... }}; private isMappable(String word) { return !forbidden.contains(word); }
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
how to do checking value
By madhuks in forum Java ServletReplies: 3Last Post: 07-21-2010, 09:35 AM -
Checking udppackets in xp
By abdullahansari in forum New To JavaReplies: 1Last Post: 05-25-2010, 03:48 AM -
Checking if a file name already has .txt in it
By AJArmstron@aol.com in forum New To JavaReplies: 2Last Post: 04-17-2010, 12:45 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks