Joachim Lippold said:
Lew said:
You might want to use standard library code for methods like
'hexValue()' rather than rolling your own. I think API calls would help
'readNumber()', too, but I'm not certain.
I considered using Integer.parseInt(String, radix) for hexValue() but
parseInt() wants a String, and i [sic] have an int. I dont want to create a
String, just for invoking parseInt().
Wha...?
Why would you use 'parseInt()'? That doesn't even match what you're
trying to do. You want to go from 'int' to 'String', right?
No, i have to go from hex code character['0'-'9','a'-'f','A'-F'](stored
as int) to int[0-15]
'parseInt()' goes from 'String' to 'int', exactly the opposite. Seems
like a strange choice to consider.
It sounds like you need to read the API docs. Why don't you do that?
http://download.oracle.com/javase/6/docs/api/java/lang/Integer.html#valueOf(java.lang.String,
int)
That actually does the same thing as Integer.parseInt(String,int),
except it gives me an instance of Integer instead of an int.
Did you read your own link? It says:
[..]
In other words, this method returns an Integer object equal to the value of:
new Integer(Integer.parseInt(s, radix))
[..]
The cause why i am using neither is:
a) my source format is (char) int
b) Both Integer.parseInt(String, int) and Integer.valueOf(String, int),
require String as input.
So i would have to use:
inv value = Integer.parseInt(Character.toString('C'),16);
This creates an unneccessary instance of String. Why should i do that?
That has nothing to do with my comment, though.
I was wondering why those were instance methods when their use is only
in a static context.
That aspect actually reduces readability.
There is a simple reason for that. Allmost all instance methods use
global variables like the JSONHandler, the Stringbuffer, the Stack and
the int.
Each parsing process is started staticly and creates his own private
context (an instance of JSONParser). This makes the parsing threadsafe.
If all these methods were static, parsing would no longer be threadsafe,
as the internal parser state would have to be static too.
Joe